package design.simdi.code.final_paper.core.entities;

import java.util.Collection;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 
 * @author Marius Dumitriu - (Jun 2, 2010 - 11:24:04 AM)
 * 
 */
/**
 * @author Marius Dumitriu - (Jun 3, 2010 - 10:17:32 PM)
 *
 */
@Entity
@Table(name = "roles")
@AttributeOverrides( { @AttributeOverride(name = "id", column = @Column(name = "Role_Id")) })
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Role extends ApplicationEntity {

	private static final long serialVersionUID = 1L;
	private String name;
	private String description;
	private Collection<UserRole> userRoles;
	private Collection<RolePermission> rolePermissions;
	/**
	 * @return the name
	 */
	@Basic(optional = false)
	@Column(length = 100, nullable = false, name = "Name")
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	@Basic(optional = false)
	@Column(length = 255, name = "Description")
	public String getDescription() {
		return description;
	}
	
	/**
	 * @param description
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	
	/**
	 * @param userRoles
	 */
	public void setUserRoles(Collection<UserRole> userRoles) {
		this.userRoles = userRoles;
	}
	
	/**
	 * @return
	 */
	@OneToMany(mappedBy = "role")	
	public Collection<UserRole> getUserRoles() {
		return userRoles;
	}
	
	/**
	 * @param rolePermissions
	 */
	public void setRolePermissions(Collection<RolePermission> rolePermissions) {
		this.rolePermissions = rolePermissions;
	}
	
	/**
	 * @return
	 */
	@OneToMany(mappedBy = "role")	
	public Collection<RolePermission> getRolePermissions() {
		return rolePermissions;
	}

}
